#pragma once

typedef unsigned int uint32_t;
typedef unsigned short uint16_t;
typedef unsigned char uint8_t;

#include "ili9341_spi.h"

typedef struct  
{		
									    
	uint16_t width;			
	uint16_t height;		
	uint16_t id;			
	uint8_t  dir;			
	uint16_t  wramcmd;	
	uint16_t  setxcmd;		
	uint16_t  setycmd;		
}_lcd_dev; 	

extern _lcd_dev lcddev;

#define USE_HORIZONTAL  	 0

#define LCD_W 240
#define LCD_H 320

extern uint16_t  POINT_COLOR;
extern uint16_t  BACK_COLOR;



#define LED      12  //back light ctrl
#define LCD_CS   8   //CS
#define LCD_RS   1       //RS DC
#define LCD_RST  14       //RST



//basic hardware op
#define	LCD_LED_ON  uapi_gpio_set_val(LED, GPIO_LEVEL_HIGH);
#define	LCD_LED_OFF  uapi_gpio_set_val(LED, GPIO_LEVEL_LOW);

//GPIO set high
#define	LCD_CS_SET  hal_gpio_output(LCD_CS, GPIO_LEVEL_HIGH);  //uapi_gpio_set_val(CONFIG_SPI_CS_MASTER_PIN, GPIO_LEVEL_HIGH); //GPIO_TYPE->BSRR=1<<LCD_CS    //Ƭѡ�˿�  	PB11 do nothing follow with spi 
#define	LCD_RS_SET	hal_gpio_output(LCD_RS, GPIO_LEVEL_HIGH);  //    uapi_gpio_set_val(LCD_RS, GPIO_LEVEL_HIGH); //GPIO_TYPE->BSRR=1<<LCD_RS    //����/����    PB10	  
#define	LCD_RST_SET	hal_gpio_output(LCD_RST, GPIO_LEVEL_HIGH);  //    uapi_gpio_set_val(LCD_RST, GPIO_LEVEL_HIGH); //GPIO_TYPE->BSRR=1<<LCD_RST   //��λ			PB12
//GPIO set low				    
#define	LCD_CS_CLR  hal_gpio_output(LCD_CS, GPIO_LEVEL_LOW);  //uapi_gpio_set_val(CONFIG_SPI_CS_MASTER_PIN, GPIO_LEVEL_LOW);//GPIO_TYPE->BRR=1<<LCD_CS     //Ƭѡ�˿�  	PB11 do nothing follow with spi 
#define	LCD_RS_CLR	hal_gpio_output(LCD_RS, GPIO_LEVEL_LOW);  //uapi_gpio_set_val(LCD_RS, GPIO_LEVEL_LOW);  //GPIO_TYPE->BRR=1<<LCD_RS     //����/����    PB10	 
#define	LCD_RST_CLR	hal_gpio_output(LCD_RST, GPIO_LEVEL_LOW);  //uapi_gpio_set_val(LCD_RST, GPIO_LEVEL_LOW); //GPIO_TYPE->BRR=1<<LCD_RST    //��λ			PB12



//color def
#define WHITE       0xFFFF
#define BLUE       	0x001F  
#define BLACK      	0x0000	  
#define BRED        0XF81F
#define GRED 	    0XFFE0
#define GBLUE	    0X07FF
#define RED         0xF800
#define MAGENTA     0xF81F
#define GREEN       0x07E0
#define CYAN        0x7FFF
#define YELLOW      0xFFE0
#define BROWN 		0XBC40 
#define BRRED 		0XFC07 
#define GRAY  		0X8430 

#define DARKBLUE      	 0X01CF
#define LIGHTBLUE      	 0X7D7C
#define GRAYBLUE       	 0X5458

#define LIGHTGREEN     	0X841F 
#define LIGHTGRAY       0XEF5B 
#define LGRAY 			0XC618 

#define LGRAYBLUE      	0XA651 
#define LBBLUE          0X2B12 

void LCD_Init(void);


void LCD_SetCursor(uint16_t Xpos, uint16_t Ypos);

// void LCD_DrawPoint(uint16_t x,uint16_t y);
// void LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
// void LCD_DrawRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);		  

void LCD_SetWindows(uint16_t xStar, uint16_t yStar,uint16_t xEnd,uint16_t yEnd);


void LCD_WriteReg(uint8_t LCD_Reg, uint16_t LCD_RegValue);

void LCD_WR_DATA(uint8_t data);

void LCD_WriteRAM_Prepare(void);

void Lcd_WriteData_16Bit(uint16_t Data);

void LCD_direction(uint8_t direction );

void LCDOutputAFrame(const uint16_t *Frame);

void LCDOutputAFrameU8(uint8_t *Frame);

void LCD_WriteRAM_Prepare(void);

void LCD_Fill(uint16_t color);

typedef struct 
{
	uint16_t width;
	uint16_t height;
	uint8_t* ptrArr;
}Image;

void LCD_DisplayImage(uint16_t x, uint16_t y, Image image);